using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public enum ButtonType 
{
    horizontal,
    vertical,
    /*left,
    right,*/
    jump,
    hook,
    attack,
}
public class VirtualContorller : MonoBehaviour
{
    public static VirtualContorller virtualContorller;

    static FixedJoystick fixedJoystick;

    bool isJump;
    bool isHook;
    bool isAttack;
    /*bool isLeft;
    bool isRight;*/

    void Awake()
    {
        virtualContorller = this;
    }

    void Start()
    {
        //获取虚拟摇杆
        fixedJoystick = transform.GetChild(0).GetComponent<FixedJoystick>();

        //跳跃按钮事件添加
        EventTrigger eventTrigger1 = transform.GetChild(1).GetComponent<EventTrigger>();
        EventTrigger.Entry click1 = new EventTrigger.Entry();
        click1.eventID = EventTriggerType.PointerDown;
        click1.callback.AddListener(JumpButtonDownEvent);

        eventTrigger1.triggers.Add(click1);

        //行动按钮事件添加
        EventTrigger eventTrigger2 = transform.GetChild(2).GetComponent<EventTrigger>();
        EventTrigger.Entry click2 = new EventTrigger.Entry();
        click2.eventID = EventTriggerType.PointerDown;
        click2.callback.AddListener(ActionButtonDownEvent);
        eventTrigger2.triggers.Add(click2);

        //攻击按钮事件添加
        EventTrigger eventTrigger3 = transform.GetChild(3).GetComponent<EventTrigger>();
        EventTrigger.Entry click3 = new EventTrigger.Entry();
        click3.eventID = EventTriggerType.PointerDown;
        click3.callback.AddListener(AttackButtonDownEvent);
        eventTrigger3.triggers.Add(click3);

        /*//左边按钮事件添加
        EventTrigger eventTrigger3 = transform.GetChild(3).GetComponent<EventTrigger>();
        EventTrigger.Entry click3 = new EventTrigger.Entry();
        click3.eventID = EventTriggerType.PointerDown;
        click3.callback.AddListener(LeftButtonDownEvent);
        eventTrigger3.triggers.Add(click3);

        //右边按钮事件添加
        EventTrigger eventTrigger4 = transform.GetChild(4).GetComponent<EventTrigger>();
        EventTrigger.Entry click4 = new EventTrigger.Entry();
        click4.eventID = EventTriggerType.PointerDown;
        click4.callback.AddListener(RightButtonDownEvent);
        eventTrigger4.triggers.Add(click4);*/
    }

    void LateUpdate()
    {
        isJump = false;
        isHook = false;
        isAttack = false;
        /*isLeft = false;
        isRight = false;*/
    }

    public static bool GetButtonDown(ButtonType type)
    {
        switch (type)
        {
            case ButtonType.jump:
                return virtualContorller.isJump;

            case ButtonType.hook:
                return virtualContorller.isHook;
            case ButtonType.attack:
                return virtualContorller.isAttack;
            /*case ButtonType.left:
                return virtualContorller.isLeft;

            case ButtonType.right:
                return virtualContorller.isRight;*/
            default:
                return false;
        }
    }

    public static float GetAxis(ButtonType type)
    {
        switch(type)
        {
            case ButtonType.horizontal:
                return fixedJoystick.Horizontal;
            case ButtonType.vertical:
                return fixedJoystick.Vertical;
        }
        return 0;
    }

    public void JumpButtonDownEvent(BaseEventData data)
    {
        isJump = true;
    }
    public void ActionButtonDownEvent(BaseEventData data)
    {
        isHook = true;
    }
    public void AttackButtonDownEvent(BaseEventData data)
    {
        isAttack = true;
    }

    /* public void LeftButtonDownEvent(BaseEventData data)
     {
         isLeft = true;
     }
     public void RightButtonDownEvent(BaseEventData data)
     {
         isRight = true;
     }*/
}
